
Public Class CongenitalDiseaseHistory

    Protected _police As New Police()
    Protected _congenital_disease As New CongenitalDisease()
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Sub New()

    End Sub

    Public Sub New(ByVal inCitizenID As String)
        LoadCongenitalDiseasesForPolice(inCitizenID)
    End Sub

    Public Property Police() As Police
        Get
            Return _police
        End Get
        Set(ByVal value As Police)
            _police = value
        End Set
    End Property

    Public Property CongenitalDisease() As CongenitalDisease
        Get
            Return _congenital_disease
        End Get
        Set(ByVal value As CongenitalDisease)
            _congenital_disease = value
        End Set
    End Property

    Public Function insertCongenitalDisease(ByVal inCongenitalDiseaseHistory As CongenitalDiseaseHistory) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_CongenitalDiseaseHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.ConvertCitizenID(inCongenitalDiseaseHistory.Police.citizen_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseID", _
                              inCongenitalDiseaseHistory.CongenitalDisease.congenital_disease_id)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCreateUser", inCongenitalDiseaseHistory.Police.create_user)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function deleteCongenitalDisease(ByVal inCongenitalDiseaseHistory As CongenitalDiseaseHistory) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_CongenitalDiseaseHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.ConvertCitizenID(inCongenitalDiseaseHistory.Police.citizen_id))
            objCmd.Parameters.Add(objParam)

            'objParam = New MySql.Data.MySqlClient.MySqlParameter("inCongenitalDiseaseID", _
            '                  inCongenitalDiseaseHistory.CongenitalDisease.congenital_disease_id)
            'objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function getCongenitalDiseaseForPolice(ByVal inCitizenID As String) As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceCongenitalDiseaseHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", inCitizenID)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "thcongenital_disease")

        Return objDs
    End Function

    Private Sub LoadCongenitalDiseasesForPolice(ByVal inCitizenID As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getCongenitalDiseasesForPolice(inCitizenID)
    End Sub


    Protected Function getCongenitalDiseasesForPolice(ByVal inCitizenID As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceCongenitalDiseaseHistory"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", inCitizenID)
        objCmd.Parameters.Add(objParam)


        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tableCongenitalDisease")

        For Each objDr As System.Data.DataRow In objDs.Tables("tableCongenitalDisease").Rows
            Dim obj As CongenitalDiseaseHistory = New CongenitalDiseaseHistory()
            obj.Police.citizen_id = objDr.Item("citizen_id").ToString()
            obj.Police.prename.prename_id = objDr.Item("prename_id").ToString()
            obj.Police.prename.prename_short_tha = objDr.Item("prename_short_tha").ToString()
            obj.Police.prename.prename_short_eng = objDr.Item("prename_short_eng").ToString()
            obj.Police.prename.prename_full_tha = objDr.Item("prename_full_tha").ToString()
            obj.Police.prename.prename_full_eng = objDr.Item("prename_full_eng").ToString()
            obj.Police.prename.order_id = objDr.Item("order_id").ToString()
            obj.Police.name = objDr.Item("name").ToString()
            obj.Police.surname = objDr.Item("surname").ToString()
            obj.Police.gender = objDr.Item("gender").ToString()
            obj.Police.birth_date = objDr.Item("birth_date").ToString()
            obj.Police.work_status.work_status_id = objDr.Item("work_status_id").ToString()
            obj.Police.work_status.work_status_name_tha = objDr.Item("work_status_name_tha").ToString()
            obj.Police.work_status.work_status_name_eng = objDr.Item("work_status_name_eng").ToString()
            obj.Police.organization.organization_id = objDr.Item("organization_id").ToString()
            obj.Police.organization.organization_name_tha = objDr.Item("organization_name_tha").ToString()
            obj.Police.organization.organization_name_eng = objDr.Item("organization_name_eng").ToString()
            obj.Police.organization.organization_parent_id = objDr.Item("organization_parent_id").ToString()
            obj.Police.organization.province.province_id = objDr.Item("province_id").ToString()
            obj.Police.organization.province.province_name_tha = objDr.Item("province_name_tha").ToString()
            obj.Police.organization.province.province_name_eng = objDr.Item("province_name_eng").ToString()
            obj.Police.commentary = objDr.Item("commentary").ToString()
            obj.Police.picture_name = objDr.Item("picture_name").ToString()
            obj.Police.folder_path = objDr.Item("folder_path").ToString()
            obj.CongenitalDisease.congenital_disease_id = objDr.Item("congenital_disease_id").ToString()
            obj.CongenitalDisease.congenital_disease_name_tha = objDr.Item("congenital_disease_name_tha").ToString()
            obj.CongenitalDisease.congenital_disease_name_eng = objDr.Item("congenital_disease_name_eng").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _police.citizen_id = _Data(_DataCurrent).police.citizen_id
            _police.prename.prename_id = _Data(_DataCurrent).police.prename.prename_id
            _police.prename.prename_short_tha = _Data(_DataCurrent).police.prename.prename_short_tha
            _police.prename.prename_short_eng = _Data(_DataCurrent).police.prename.prename_short_eng
            _police.prename.prename_full_tha = _Data(_DataCurrent).police.prename.prename_full_tha
            _police.prename.prename_full_eng = _Data(_DataCurrent).police.prename.prename_full_eng
            _police.prename.order_id = _Data(_DataCurrent).police.prename.order_id
            _police.name = _Data(_DataCurrent).police.name
            _police.surname = _Data(_DataCurrent).police.surname
            _police.gender = _Data(_DataCurrent).police.gender
            _police.birth_date = _Data(_DataCurrent).police.birth_date
            _police.work_status.work_status_id = _Data(_DataCurrent).police.work_status.work_status_id
            _police.work_status.work_status_name_tha = _Data(_DataCurrent).police.work_status.work_status_name_tha
            _police.work_status.work_status_name_eng = _Data(_DataCurrent).police.work_status.work_status_name_eng
            _police.organization.organization_id = _Data(_DataCurrent).police.organization.organization_id
            _police.organization.organization_name_tha = _Data(_DataCurrent).police.organization.organization_name_tha
            _police.organization.organization_name_eng = _Data(_DataCurrent).police.organization.organization_name_eng
            _police.organization.organization_parent_id = _Data(_DataCurrent).police.organization.organization_parent_id
            _police.organization.province.province_id = _Data(_DataCurrent).police.organization.province.province_id
            _police.organization.province.province_name_tha = _Data(_DataCurrent).police.organization.province.province_name_tha
            _police.organization.province.province_name_eng = _Data(_DataCurrent).police.organization.province.province_name_eng
            _police.commentary = _Data(_DataCurrent).police.commentary
            _police.picture_name = _Data(_DataCurrent).police.picture_name
            _police.folder_path = _Data(_DataCurrent).police.folder_path
            _congenital_disease.congenital_disease_id = _Data(_DataCurrent).CongenitalDisease.congenital_disease_id
            _congenital_disease.congenital_disease_name_tha = _Data(_DataCurrent).CongenitalDisease.congenital_disease_name_tha
            _congenital_disease.congenital_disease_name_eng = _Data(_DataCurrent).CongenitalDisease.congenital_disease_name_eng
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

End Class
